Element.childElementNodes = function(element) {
  return $A($(element).childNodes).select(function(node) {
    return node.nodeType == Node.ELEMENT_NODE;
  });
};

String.prototype.addQueryParams = function(hash) {
  var match = location.href.match(/^([^\?]*)(\?.*)?$/);
  var url = match[1] || '';
  var params = (match[2] || '').toQueryParams();
  for (var key in hash) {
    params[key] = hash[key];
  }
  for (key in params) {
    if (params[key] == '')
      delete params[key];
  }
  var query = $H(params).toQueryString();
  if (query) url += '?' + query;
  return url;
}

function setupSelectableInput(select, field) {
  select = $(select);
  field = $(field);

  var setValue = function() {
    var value = select.value;
    if (value == '入力する...') {
      field.show();
      field.value = '';
      field.activate();
    } else {
      field.hide();
      field.value = value;
    }
  };
  if (field.value && select.value != field.value) {
    select.value = '入力する...';
    field.show();
  } else {
    setValue();
  }
  select.observe('change', setValue);
}